home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg2.cab / table_rows.xsl < prev    next >
Extensible Markup Language  |  2005-09-10  |  10KB  |  244 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: table_rows.xsl,v $
  7.  
  8.     $Revision: 1.6 $
  9.  
  10.     last change: $Author: rt $ $Date: 2005/09/08 22:03:20 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35. -->
  36. <!--
  37.     For further documentation and updates visit http://xml.openoffice.org/sx2ml
  38. -->
  39. <xsl:stylesheet version="1.0"
  40.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  41.     xmlns:office="http://openoffice.org/2000/office"
  42.     xmlns:style="http://openoffice.org/2000/style"
  43.     xmlns:text="http://openoffice.org/2000/text"
  44.     xmlns:table="http://openoffice.org/2000/table"
  45.     xmlns:draw="http://openoffice.org/2000/drawing"
  46.     xmlns:fo="http://www.w3.org/1999/XSL/Format"
  47.     xmlns:xlink="http://www.w3.org/1999/xlink"
  48.     xmlns:number="http://openoffice.org/2000/datastyle"
  49.     xmlns:svg="http://www.w3.org/2000/svg"
  50.     xmlns:chart="http://openoffice.org/2000/chart"
  51.     xmlns:dr3d="http://openoffice.org/2000/dr3d"
  52.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  53.     xmlns:form="http://openoffice.org/2000/form"
  54.     xmlns:script="http://openoffice.org/2000/script"
  55.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  56.     xmlns:meta="http://openoffice.org/2000/meta"
  57.     xmlns:config="http://openoffice.org/2001/config"
  58.     xmlns:help="http://openoffice.org/2000/help"
  59.     exclude-result-prefixes="office style text table draw fo xlink number svg chart dr3d math form script dc meta config help">
  60.  
  61.  
  62.     <xsl:param name="rowElement" select="'tr'" />
  63.  
  64.     <!-- ********************************** -->
  65.     <!-- *** write repeating table rows *** -->
  66.     <!-- ********************************** -->
  67.  
  68.     <!-- current node is a table:table or table:sub-table -->
  69.     <xsl:template name="create-table-rows">
  70.         <xsl:param name="globalData" />
  71.         <xsl:param name="allVisibleTableRows" />
  72.         <xsl:param name="allTableColumns" />
  73.  
  74.         <!-- Some Office Calc documents simulate a background by repeating one of the later cells until end of used space
  75.              (The value of "table:number-columns-repeated" is enourmous). Writing out all these cells would be fatal in time
  76.              and output size. Therefore, this global variable shows us the longest row with content. -->
  77.         <xsl:variable name="maxRowLength" select="count($allTableColumns/table:table-column)" />
  78.         <xsl:if test="$debugEnabled">
  79.             <xsl:message>maxRowLength: <xsl:value-of select="$maxRowLength" /></xsl:message>
  80.             <xsl:call-template name="table-debug-allTableColumns">
  81.                 <xsl:with-param name="allTableColumns" select="$allTableColumns" />
  82.             </xsl:call-template>
  83.         </xsl:if>
  84.  
  85.         <!-- a table is a table header, when it has a "table:table-header-rows" ancestor -->
  86.         <xsl:variable name="tableDataType">
  87.             <xsl:choose>
  88.                 <xsl:when test="ancestor::table:table-header-rows">
  89.                     <xsl:text>th</xsl:text>
  90.                 </xsl:when>
  91.                 <xsl:otherwise>
  92.                     <xsl:text>td</xsl:text>
  93.                 </xsl:otherwise>
  94.             </xsl:choose>
  95.         </xsl:variable>
  96.  
  97.         <xsl:choose>
  98.             <xsl:when test="$outputType = 'WML'">
  99.                 <xsl:for-each select="$allVisibleTableRows">
  100.                     <xsl:call-template name="wml-repeat-write-row">
  101.                         <xsl:with-param name="globalData"           select="$globalData" />
  102.                         <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  103.                         <xsl:with-param name="numberRowsRepeated"   select="@table:number-rows-repeated" />
  104.                         <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  105.                     </xsl:call-template>
  106.                 </xsl:for-each>
  107.             </xsl:when>
  108.             <xsl:otherwise>
  109.                 <!-- removes repetition of rows, most probably done for background emulating -->
  110.                 <xsl:for-each select="$allVisibleTableRows">
  111.                     <xsl:choose>
  112.                         <xsl:when test="(last() or (last() - 1)) and @table:number-rows-repeated > 99">
  113.                             <xsl:call-template name="repeat-write-row">
  114.                                 <xsl:with-param name="globalData"           select="$globalData" />
  115.                                 <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  116.                                 <xsl:with-param name="numberRowsRepeated"   select="1" />
  117.                                 <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  118.                                 <xsl:with-param name="tableDataType"        select="$tableDataType" />
  119.                             </xsl:call-template>
  120.                         </xsl:when>
  121.                         <xsl:otherwise>
  122.                             <xsl:call-template name="repeat-write-row">
  123.                                 <xsl:with-param name="globalData"           select="$globalData" />
  124.                                 <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  125.                                 <xsl:with-param name="numberRowsRepeated"   select="@table:number-rows-repeated" />
  126.                                 <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  127.                                 <xsl:with-param name="tableDataType"        select="$tableDataType" />
  128.                             </xsl:call-template>
  129.                         </xsl:otherwise>
  130.                     </xsl:choose>
  131.                 </xsl:for-each>
  132.             </xsl:otherwise>
  133.         </xsl:choose>
  134.     </xsl:template>
  135.  
  136.  
  137.     <xsl:template name="repeat-write-row">
  138.         <xsl:param name="globalData" />
  139.         <xsl:param name="allTableColumns" />
  140.         <xsl:param name="numberRowsRepeated" select="1" />
  141.         <xsl:param name="maxRowLength" />
  142.         <xsl:param name="tableDataType" />
  143.  
  144.         <xsl:choose>
  145.             <!-- write an entry of a row and repeat calling this method until all elements are written out -->
  146.             <xsl:when test="$numberRowsRepeated > 1 and table:table-cell">
  147.                 <xsl:call-template name="write-row">
  148.                     <xsl:with-param name="globalData"       select="$globalData" />
  149.                     <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
  150.                     <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
  151.                     <xsl:with-param name="tableDataType"    select="$tableDataType" />
  152.                 </xsl:call-template>
  153.  
  154.                 <!-- NOTE: take variable from the output of repeated write-row and iterate giving out the variable -->
  155.                 <xsl:call-template name="repeat-write-row">
  156.                     <xsl:with-param name="globalData"           select="$globalData" />
  157.                     <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  158.                     <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  159.                     <xsl:with-param name="numberRowsRepeated"   select="$numberRowsRepeated - 1" />
  160.                     <xsl:with-param name="tableDataType"        select="$tableDataType" />
  161.                 </xsl:call-template>
  162.             </xsl:when>
  163.             <!-- write a single entry of a row -->
  164.             <xsl:otherwise>
  165.                 <xsl:call-template name="write-row">
  166.                     <xsl:with-param name="globalData"           select="$globalData" />
  167.                     <xsl:with-param name="allTableColumns"      select="$allTableColumns" />
  168.                     <xsl:with-param name="maxRowLength"         select="$maxRowLength" />
  169.                     <xsl:with-param name="tableDataType"        select="$tableDataType" />
  170.                 </xsl:call-template>
  171.             </xsl:otherwise>
  172.         </xsl:choose>
  173.     </xsl:template>
  174.  
  175.  
  176.     <xsl:template name="add-table-row-attributes">
  177.         <xsl:param name="globalData" />
  178.  
  179.         <!-- writing the style of the row -->
  180.         <xsl:if test="@table:style-name">
  181.             <xsl:call-template name='add-style-properties'>
  182.                 <xsl:with-param name="globalData" select="$globalData" />
  183.             </xsl:call-template>
  184.         </xsl:if>
  185.     </xsl:template>
  186.  
  187.     <xsl:template name="write-row">
  188.         <xsl:param name="globalData" />
  189.         <xsl:param name="allTableColumns" />
  190.         <xsl:param name="maxRowLength" />
  191.         <xsl:param name="tableDataType" />
  192.  
  193.  
  194.         <xsl:element namespace="{$namespace}" name="{$rowElement}">
  195.             <xsl:call-template name='add-table-row-attributes'>
  196.                 <xsl:with-param name="globalData" select="$globalData" />
  197.             </xsl:call-template>
  198.  
  199.             <xsl:if test="$debugEnabled">
  200.                 <xsl:message>'tr' element has been added!</xsl:message>
  201.             </xsl:if>
  202.  
  203.             <xsl:apply-templates select="table:table-cell">
  204.                 <xsl:with-param name="globalData"       select="$globalData" />
  205.                 <xsl:with-param name="allTableColumns"  select="$allTableColumns" />
  206.                 <xsl:with-param name="maxRowLength"     select="$maxRowLength" />
  207.                 <xsl:with-param name="tableDataType"    select="$tableDataType" />
  208.             </xsl:apply-templates>
  209.  
  210.         </xsl:element>
  211.     </xsl:template>
  212.  
  213.  
  214.     <!-- **************************** -->
  215.     <!-- *** HELPER: table styles *** -->
  216.     <!-- **************************** -->
  217.  
  218.     <xsl:template name="add-style-properties">
  219.         <xsl:param name="globalData" />
  220.         <xsl:param name="allTableColumns" />
  221.         <xsl:param name="node-position" />
  222.  
  223.         <xsl:choose>
  224.             <!--+++++ CSS (CASCADING STYLE SHEET) HEADER STYLE WAY +++++-->
  225.             <xsl:when test="$outputType = 'CSS_HEADER'">
  226.                 <xsl:attribute name="class">
  227.                     <xsl:value-of select="translate(@table:style-name, '. %()/\+', '')" />
  228.                 </xsl:attribute>
  229.             </xsl:when>
  230.  
  231.             <!--+++++ HTML 4.0 INLINED WAY  +++++-->
  232.             <xsl:when test="$outputType = 'CSS_INLINED'">
  233.                 <xsl:attribute name="style">
  234.                     <xsl:value-of select="$globalData/all-styles/style[@style:name = current()/@table:style-name]/final-properties" />
  235.                 </xsl:attribute>
  236.             </xsl:when>
  237.         </xsl:choose>
  238.     </xsl:template>
  239.  
  240.     <!-- default template to be overwritten -->
  241.     <xsl:template name="wml-repeat-write-row" />
  242.  
  243. </xsl:stylesheet>
  244.